//
//  HomeCenterView.m
//  YZMicroStock
//
//  Created by 王慕铁 on 2017/12/11.
//  Copyright © 2017年 cqjr. All rights reserved.
//

#import "HomeCenterView.h"
#import "UIView+SubView.h"

@interface HomeCenterView()

@property (nonatomic , strong) UIImageView* imageView;
@property (nonatomic , strong) UILabel*     title;
@property (nonatomic , strong) UILabel*     detail;
@property (nonatomic , strong) UIImageView* imageT;

@end

@implementation HomeCenterView

- (UIImageView *)imageView {
    if (!_imageView) {
        _imageView = [UIImageView new];
        _imageView.contentMode =  UIViewContentModeScaleAspectFit;
    }
    return _imageView;
}

- (UILabel *)title {
    if (!_title) {
        _title = [UILabel new];
        _title.textColor = [UIColor whiteColor];
        _title.font = [UIFont systemFontOfSize: iPhone5 ? 12 : 14];
    }
    return _title;
}

- (UILabel *)detail {
    if (!_detail) {
        _detail = [UILabel new];
        _detail.textColor = [YZMAppStyle colorForLightGrayText];
        _detail.numberOfLines = 0;
        _detail.font = [UIFont systemFontOfSize:iPhone5 ? 10 : 12];
    }
    return _detail;
}

- (UIImageView *)imageT {
    if (!_imageT) {
        _imageT = [UIImageView new];
    }
    return _imageT;
}

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self createView];
        self.backgroundColor = [YZMAppStyle colorForMain];
        [YZMSetBorderAndCornerRadius setView:self borderWidth:1 borderColor:[YZMAppStyle colorForLineOfCell] cornerRadius:5];
    }
    return self;
}

- (void)createView {
    
    [self addSubviews:@[self.imageView,self.title,self.detail,self.imageT]];
    
    [self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.mas_centerY);
        make.left.equalTo(self.mas_left).offset( iPhone5 ? 10 : 20);
        if (iPhone5) {
            make.width.mas_equalTo(25);
            make.height.mas_equalTo(25);
        } else {
            make.width.mas_equalTo(30);
            make.height.mas_equalTo(30);
        }
    }];
    
    [self.title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.imageView.mas_right).offset(10);
//        if (iPhone5) {
//            make.top.equalTo(self.imageView.mas_top).offset(-10);
//        } else {
//            make.top.equalTo(self.imageView.mas_top);
//        }
        make.bottom.equalTo(self.imageView.mas_centerY).offset(-2);
    }];
    
    [self.detail mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.title.mas_left);
        make.top.equalTo(self.title.mas_bottom).offset(5);
        make.right.equalTo(self.mas_right).offset(-5);
    }];
    
    [self.imageT mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.title.mas_right).offset(iPhone5 ? 5 : 10);
        make.top.equalTo(self.title.mas_top);
        make.height.mas_equalTo(15);
        make.width.mas_equalTo(35);
    }];
    
}

- (void)setImage:(NSString *)imageStr title:(NSString *)title detail:(NSString *)detail imageT:(NSString *)imageT {
    
    _imageView.image = [UIImage imageNamed:imageStr];
    _title.text = title;
    _detail.text = detail;
    _imageT.image = [UIImage imageNamed:imageT];
    
    
}

- (void)addTarget:(id)target action:(SEL)action {
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:target action:action];
    tap.numberOfTapsRequired = 1;
    [self addGestureRecognizer:tap];
 
}

@end
